/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package klasy;

import java.awt.image.BufferedImage;
import java.io.BufferedWriter;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Serializable;
import javax.imageio.ImageIO;
import javax.imageio.stream.FileImageInputStream;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author Cyga
 */
@Entity
@Table(name = "lek", catalog = "medycyna", schema = "")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Lek.findAll", query = "SELECT l FROM Lek l"),
    @NamedQuery(name = "Lek.findByIdLek", query = "SELECT l FROM Lek l WHERE l.idLek = :idLek"),
    @NamedQuery(name = "Lek.findByNazwaLek", query = "SELECT l FROM Lek l WHERE l.nazwaLek = :nazwaLek"),
    @NamedQuery(name = "Lek.findBySkladLek", query = "SELECT l FROM Lek l WHERE l.skladLek = :skladLek"),
    @NamedQuery(name = "Lek.findByOpisLek", query = "SELECT l FROM Lek l WHERE l.opisLek = :opisLek"),
    @NamedQuery(name = "Lek.findByDawkowanie", query = "SELECT l FROM Lek l WHERE l.dawkowanie = :dawkowanie")})
public class Lek implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @Column(name = "id_lek")
    private Integer idLek;
    @Basic(optional = false)
    @Column(name = "nazwa_lek")
    private String nazwaLek;
    @Basic(optional = false)
    @Column(name = "sklad_lek")
    private String skladLek;
    @Basic(optional = false)
    @Column(name = "opis_lek")
    private String opisLek;
    @Basic(optional = false)
    @Column(name = "dawkowanie")
    private String dawkowanie;
    @Basic(optional = false)
    @Lob
    @Column(name = "zdjecie_lek")
    private byte[] zdjecieLek;

    public Lek() {
    }

    public Lek(Integer idLek) {
        this.idLek = idLek;
    }

    public Lek(Integer idLek, String nazwaLek, String skladLek, String opisLek, String dawkowanie, byte[] zdjecieLek) {
        this.idLek = idLek;
        this.nazwaLek = nazwaLek;
        this.skladLek = skladLek;
        this.opisLek = opisLek;
        this.dawkowanie = dawkowanie;
        this.zdjecieLek = zdjecieLek;
    }

    public Integer getIdLek() {
        return idLek;
    }

    public void setIdLek(Integer idLek) {
        this.idLek = idLek;
    }

    public String getNazwaLek() {
        return nazwaLek;
    }

    public void setNazwaLek(String nazwaLek) {
        this.nazwaLek = nazwaLek;
    }

    public String getSkladLek() {
        return skladLek;
    }

    public void setSkladLek(String skladLek) {
        this.skladLek = skladLek;
    }

    public String getOpisLek() {
        return opisLek;
    }

    public void setOpisLek(String opisLek) {
        this.opisLek = opisLek;
    }

    public String getDawkowanie() {
        return dawkowanie;
    }

    public void setDawkowanie(String dawkowanie) {
        this.dawkowanie = dawkowanie;
    }

    public BufferedImage getZdjecieLek() throws IOException {
        BufferedImage img = ImageIO.read(new ByteArrayInputStream(zdjecieLek));
        String content = null;
        /* 
         try {
 
         content = "C:\\Users\\Cyga\\Documents\\NetBeansProjects\\Medycyna\\web\\plik.bmp";
 
         File file = null ;
 
         // if file doesnt exists, then create it
			
         file.createNewFile();
			
 
         FileWriter fw = new FileWriter(file.getAbsoluteFile());
         BufferedWriter bw = new BufferedWriter(fw);
         bw.write(content);
         bw.close();
 
         ImageIO.write(img, "bmp", file);
 
         } catch (IOException e) {
         e.printStackTrace();
         }
	
         */

        //System.out.print(content);
        return img;

        //return "C:\\Users\\Cyga\\Documents\\lenac.bmp";
    }

    public void setZdjecieLek(byte[] zdjecieLek) {
        this.zdjecieLek = zdjecieLek;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idLek != null ? idLek.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Lek)) {
            return false;
        }
        Lek other = (Lek) object;
        if ((this.idLek == null && other.idLek != null) || (this.idLek != null && !this.idLek.equals(other.idLek))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "klasy.Lek[ idLek=" + idLek + " ]";
    }

}
